<!DOCTYPE HTML PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
	<title>菜单管理 </title>
	<#include '/commons/include/head.ftl'>
</head>

<body>

	<div id="tg">
		<div id="toolbars" style="display:none;">
			<form id="searchForm">
				<div class="datagrid-toolbars">
					<div class="toolbar-row">
						<div class="group">
							<a onclick="reload();" href="javascript:;" class="bto"><i class="fa fa-refresh bto icon-green"></i>刷新</a>
							<div class="tools_separator"></div>
							<a onclick="form_dialog('add');" href="javascript:;" class="bto"><i class="fa fa-plus bto icon-green"></i>新增</a>
							<a onclick="form_dialog('update');" href="javascript:;" class="bto"><i class="fa fa-pencil bto icon-green1"></i>编辑</a>
							<a onclick="del();" href="javascript:;" class="bto"><i class="fa fa-trash bto icon-red"></i>删除</a>
							<a onclick="detail();" href="javascript:;" class="bto"><i class="fa fa-align-justify bto icon-blue"></i>详细</a>
							<div class="tools_separator"></div>
							<a href="javascript:;" class="easyui-menubutton dropdown bto" data-options="menu: '#c'">
								<i class="fa fa-home bto icon-blue"></i>帮助中心
							</a>
							<div id="c" class="easyui-menu" style="width: 140px;">
							    <div id="main-info" data-options="iconCls: 'icon-hamburg-hire-me'">查看帮助</div>
							    <div id="main-changePassword" data-options="iconCls: 'icon-hamburg-lock'">反馈建议</div>
							    <div id="main-record" data-options="iconCls: 'icon-hamburg-print'">技术支持</div>
							    <div class="menu-sep"></div>
							    <div id="logoutSystem" data-options="iconCls: 'icon-hamburg-sign-out'">关于我们</div>
							</div>
						</div>
					</div>
				</div>
				<div class="datagrid-toolbars top-line">
					<div class="toolbar-row">
						<div class="group">
							<div class="form-inputs">
								<div class="sbox left-10">
									<input class="easyui-searchbox" data-options="prompt:'请输入关键字', height: 31" style="width:200px"></input>
								</div>
								<a onclick="form_dialog('add');" href="javascript:;" class="">搜索</a>
								<a onclick="form_dialog('add');" href="javascript:;" class="">重置</a>
							</div>
						</div>
					</div>
				</div>
			</form>
		</div>
	</div>
	
	
	<script>
	var $tg ;
	$(function(){
		$tg = $("#tg").treegrid({
			/*title: '<div class="icon-div"><i class="fa fa-list fa-120 pt-2 icon-blue"></i></div>菜单管理',*/ 
			method: "GET",
			url: "${ctx}/manager/system/menu/treegrid",
            idField: "id", treeField: "text", fit: true, 
            border: false, striped:true, singleSelect: true,rownumbers: true, 
            toolbar: "#toolbars", sortName: 'sorting', sortOrder: 'asc', queryParams: {},
            frozenColumns: [[
                { field: "id", title: "ID", width: 50, sortable: true, hidden: true } 
            ]],
            columns: [[
                { field: "text", title: "名称", width: 180 },
                { field: "location", title: "访问地址", width: 350 },
                { field: "code", title: "权限编码", width: 120 },
                { field: "operation", title: "操作权限", width: 200, formatter:function(value,row){
                	var str = [] ;
                	if(undefined != row.permits && row.permits.length > 0) {
                		$.each(row.permits, function(i, p){
		                	str.push("&nbsp;"+p.fullName);
                		});
                	}
                	return str.join(",") ;	
                }}, 
                { field: "enabled", title: "是否禁用", width: 60, sortable: true, align: "center", formatter:function(value,row){
                	return (value==1?"正常":"<span style='color: red;'>禁用</span>") ;	
                }},
                { field: "sortCode", title: "排序", width: 50, align: "center", sortable: true },
                { field: "createTime", title: "创建时间", width: 150, sortable: true, align: "center", formatter:function(value,row){
                	return (undefined != value?$.date.format(value, "yyyy-MM-dd HH:mm:ss"):"") ;	
                }},
                { field: "createUserName", title: "创建用户", width: 80, align: "center" },
                { field: "modifyTime", title: "修改时间", width: 150, sortable: true, align: "center", formatter:function(value,row){
                	return (undefined != value?$.date.format(value, "yyyy-MM-dd HH:mm:ss"):"") ;	
                }},
                { field: "modifyUserName", title: "修改用户", width: 80, align: "center" }
            ]],
            onLoadSuccess: function(){
            	$.fn.treegrid.extensions.onLoadSuccess.apply(this, arguments);
            	$tg.treegrid('unselectAll');$tg.treegrid('clearSelections');
            },
            enableHeaderClickMenu: true, enableHeaderContextMenu: true, enableRowContextMenu: false
        });
	});
	
	
	function reload(){$tg.treegrid("reload") ;}
	function getIds() {
		var rows = $tg.treegrid('getChecked');
		var ids = [];
		if (rows.length > 0) {
			for ( var i = 0; i < rows.length; i++) {
				if(undefined != rows[i].id && ""!=rows[i].id) {
					ids.push(rows[i].id);
				}
			}
		}
		return ids ;
	}	
	
	function form_dialog(formType) {
		var form_url = "${ctx}/manager/system/menu/form";
		if(formType === "update") {
			var ids = getIds() ;
			if(ids.length == 0) {alertify.warning("请选择一条记录！");return;}
			if(ids.length > 1) {alertify.warning("只能编辑一条记录！");return;}
			form_url = "${ctx}/manager/system/menu/form?id="+ids[0];
		}
		
		var $d = $.easyui.showDialog({
			title: '<div class="icon-div"><i class="fa fa-th-large fa-120 pt-2 icon-blue"></i></div> 表单', 
			href: form_url, 
			iniframe: false, topMost: true, iconCls : '',
			width: 610, height: 350, maximizable: true,
            enableApplyButton: false, enableCloseButton: false, enableSaveButton: false,
            buttons : [ 
              { text : '<i class="fa fa-save fa-120 mt-6 icon-green"></i> 应用', handler : function() { $.easyui.parent.submitForm($d, $tg, true) ; } },
              { text : '<i class="fa fa-save fa-120 mt-6 icon-blue"></i> 保存', handler : function() { $.easyui.parent.submitForm($d, $tg) ; } },
              { text : '<i class="fa fa-remove fa-120 mt-6 icon-red"></i> 关闭', handler : function() { $d.dialog('destroy'); } } 
           	]
        });
	}
	
	function del() {
		var node = $tg.treegrid("getSelected");
		if(undefined == node || null == node) {alertify.warning("请选择一条记录！");return;}
		$.messager.confirm("您确定要进行该操作？", function (c) { 
			if(c) {
				$.easyui.loading({ msg: "数据删除中，请稍等..."});
				deletedAjax("${ctx}/manager/system/menu/delete/"+node.id, {}) ;
			}
		});
	}
	function deletedAjax(url, params) {
		$.ajax({
			url: url,
			type: "DELETE", dataType: "JSON",
			success: function(result) {
				if (result.status) {
					$tg.treegrid("unselectAll");$tg.treegrid("reload") ;
					alertify.success(result.message);
					$.easyui.loaded();
				} else {
					alertify.warning(result.message);
					$.easyui.loaded();
				}
			},
			complete: function(XMLHttpRequest, textStatus){},
			error: function(XMLHttpRequest, textStatus, errorThrown){
				$.easyui.loaded();
				if(XMLHttpRequest.status == 403) {
					$.messager.alert(XMLHttpRequest.statusText, XMLHttpRequest.responseText, "warning");
				} else {
					$.messager.alert("错误", XMLHttpRequest.status + "：发生未知错误", "error");
				}
			}
		});
	}
	</script>
</body>
</html>

